//---------------------------------------------------------------------------

#ifndef InvoiceBridgeH
#define InvoiceBridgeH

#include "Sequence.h"
#include "StringUtilities.h"
#include "PaymentTypeBridge.h"

#define NO_ID 0

#define MIN_INVOICE_NUM 1
#define MAX_INVOICE_NUM 8

class TInvoice : public TObject
{
   public:
      __int64 id;
      TDateTime date;
      __int64 page;
      __int64 invoiceID;
      float amount;
      TPaymentType* paymentType;
      bool  isCanceled;

      TInvoice();
      TInvoice( TInvoice* other);
      virtual __fastcall ~TInvoice();
      bool IsEqual( TInvoice* other); 
};

class TInvoiceBridge
{
   public:
      TInvoiceBridge( TDatabase * database);
      ~TInvoiceBridge();

      __int64 GetLastID();
      __int64 GetNextID();

      bool IsExist( __int64 pageID, __int64 invoiceID);
      void Get( __int64 id, TInvoice* invoice);
      void Add( __int64 id, TInvoice* invoice);
      void Update( __int64 id, TInvoice* invoice);
      void Delete( __int64 id);
      void Cancel( __int64 id);
      void GetInvoices( TStrings * invoices);
      void GetPageInvoices( __int64 pageID, TStrings * invoices);

   private:
      TSequence * sequence;

      TQuery * qryExists;
      TQuery * qryGet;
      TQuery * qryAdd;
      TQuery * qryUpdate;
      TQuery * qryDelete;
      TQuery * qryCancel;
      TQuery * qryGetInvoices;
      TQuery * qryGetPageInvoices;
      TQuery * qryGetLastInvoiceNumber;

      void BuildExistsQuery();
      void BuildGetQuery();
      void BuildAddQuery();
      void BuildUpdateQuery();
      void BuildDeleteQuery();
      void BuildCancelQuery();
      void BuildGetInvoicesQuery();
      void BuildGetPageInvoicesQuery();
};

#endif
